<?php
/**
 * 酒店管理
 * User: lxq
 * Date: 2018/3/15
 * Time: 10:23
 */
defined('InNcPHP') or exit('Access Invalid!');
class hotelControl  extends  SystemControl {

    private $links = array(
        array('url'=>'act=hotel&op=index','lang'=>'nc_manage'),
        array('url'=>'act=hotel&op=add','lang'=>'nc_new'),
    );

    public function __construct(){
        parent::__construct();
        Tpl::setDir('hotel');
        Language::read('ticket');
    }

    /**
     * 酒店列表
     */
    public  function indexOp(){
        $merchant_model = Model('member_merchant');
        $category_model = Model('ticket_category');
        //查询条件
        $condition =array();
        if(isset($_GET['search_title']) && $_GET['search_title']){
            $condition['hotel_name'] = array('like','%'.$_GET['search_title'].'%');
        }
        if (isset($_GET['search_state']) && is_numeric($_GET['search_state'])) {
            $condition['ht_status'] = intval($_GET['search_state']);
        }
        if (isset($_GET['search_cate1']) && is_numeric($_GET['search_cate1'])) {
            $condition['cate_id'] = intval($_GET['search_cate1']);
        }
        $merchant_id = intval($this->admin_info['merchant_id']);
        if($merchant_id>0){
            $condition['merchant_id'] = $merchant_id;
        }else{
            if (isset($_GET['search_merchant']) && is_numeric($_GET['search_merchant'])) {
                $condition['merchant_id'] = intval($_GET['search_merchant']);
            }
        }

        $day = getgpc('day');
        if($day=='today'){
            $time_from = $time_to = strtotime(date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d"),date("Y")))) ;
            $time_to = $time_to + 86400;
            $condition['ht_add_time'] = array('between',array($time_from,$time_to));
        }

        /* @var hotelModel $hotel_model*/
        $hotel_model = Model('hotel');
        $hotels = $hotel_model->getHotelListPage($condition, '*', 10);
        $cates = $category_model->getCategoryList();
        if($hotels){
            foreach ($hotels as $k => $ticket) {
                $hotels[$k]['shop_name'] = $merchant_model->getfby_merchant_id($ticket['merchant_id'], 'mc_shop_name');
                $hotels[$k]['hotel_thumb'] = UPLOAD . 'hotel/' . $ticket['hotel_thumb'];
                foreach ($cates as $cate) {
                    if ($ticket['cate_id'] == $cate['tc_id']) {
                        $hotels[$k]['cate_id'] = $cate['tc_name'];
                    } else if ($ticket['tk_cate2'] == $cate['tc_id']) {
                        $hotels[$k]['tk_cate2'] = $cate['tc_name'];
                    }
                }
            }
        }
        $cate1 = $category_model->getCategoryList(array('tc_pid'=>HOTEL_MARK,'is_del'=>0));//酒店底下所有分类
        if(intval($this->admin_info['merchant_id'])>0){
            $merchants = $merchant_model->getMerchantList(array('mc_status'=>1,'merchant_id'=>$this->admin_info['merchant_id']), 'merchant_id,mc_shop_name');
        }else{
            $merchants = $merchant_model->getMerchantList(array('mc_status'=>1,'is_disable'=>0), 'merchant_id,mc_shop_name');
        }

        Tpl::output('cate1',$cate1);
        Tpl::output('search', $_GET);
        Tpl::output('merchants', $merchants);
        Tpl::output('hotels',$hotels);
        Tpl::output('page',$hotel_model->showpage());
        Tpl::output('top_link',$this->sublink($this->links,'index'));
        Tpl::showpage('hotel.index');
    }

    /**
     * 添加酒店
     */
    public function addOp()
    {
        /* @var member_merchantModel $merchant_model */
        $merchant_model = Model('member_merchant');
        if(intval($this->admin_info['merchant_id'])>0){
            $merchants = $merchant_model->getMerchantList(array('mc_status'=>1,'merchant_id'=>$this->admin_info['merchant_id']), 'merchant_id,mc_shop_name');
        }else{
            $merchants = $merchant_model->getMerchantList(array('mc_status'=>1,'is_disable'=>0), 'merchant_id,mc_shop_name');
        }
        $area_model = Model('area');
        $ticket_category = Model('ticket_category');
        if(chksubmit()){
            $hotel_model = Model('hotel');
            $insert_array = array();
            $insert_array['hotel_name']          = trim($_POST['title']);
            $insert_array['merchant_id']         = intval($this->admin_info['merchant_id'])>0?intval($this->admin_info['merchant_id']):intval($_POST['merchant_id']);
            $insert_array['ht_market_price']     = floatval($_POST['show_price']);
            $insert_array['hotel_tel']           = $_POST['hotel_tel'];
            $insert_array['ht_add_time']         = time();
            $insert_array['ht_update_time']      = time();
            $insert_array['ht_addr']             = $_POST['addr'];
            $insert_array['ht_province_id']      = $_POST['province_id'];
            $insert_array['ht_city_id']          = $_POST['city_id'];
            $insert_array['ht_city_name']        = $area_model->getfby_area_id($_POST['city_id'],'name');
            $insert_array['ht_area_id']          = $_POST['area_id'];
            $insert_array['hotel_param_wifi']    = trim($_POST['hotel_param_wifi']);
            $insert_array['hotel_param_part']    = trim($_POST['hotel_param_part']);
            $insert_array['hotel_param_room']    = implode(',', $_POST['hotel_param_room']);
            $insert_array['hotel_param_service'] = implode(',', $_POST['hotel_param_service']);
            $insert_array['hotel_param_base']    = implode(',', $_POST['hotel_param_base']);
            $insert_array['hotel_content']       = $_POST['content'];
            $insert_array['cate_id']             = intval($_POST['cate1']);
            $store_location = trim($_POST['store_location']);
            $store_gps = explode(',', $store_location);
            $insert_array['hotel_lat']  = $store_gps[1];//纬度
            $insert_array['hotel_lng']  = $store_gps[0];//经度
            $insert_array['ht_full_addr']        = implode('',array(
                $area_model->getfby_area_id(intval($_POST['province_id']),'name'),
                $insert_array['ht_city_name'],
                $area_model->getfby_area_id(intval($_POST['area_id']),'name'),
                $_POST['addr']
            ));

            $upload = new UploadFile();
            $upload->set('default_dir','hotel/'.$upload->getSysSetPath());
            $upload->set('thumb_width', GOODS_IMAGES_WIDTH);
            $upload->set('thumb_height', GOODS_IMAGES_HEIGHT);
            $upload->set('thumb_ext', GOODS_IMAGES_EXT);
            $upload->set('allow_type', array('gif', 'jpg', 'jpeg', 'png'));
            //封面图片
            $result = $upload->upfile('thumb');
            if($result){
                $insert_array['hotel_thumb'] = $upload->getSysSetPath() . $upload->file_name;
            } else {
                //图片上传失败
                $this->log('酒店封面图上传失败'.'[标题:'.$_POST['title'].']',0);
                showMessage(L('nc_common_save_fail').$upload->error);
            }
            $result = $hotel_model->addHotel($insert_array);
            if($result){
                $spec_model = Model('spec');
                $data = array(
                    'goods_id' =>$result,
                    'add_time' =>time(),
                    'type' =>1 //酒店
                );
                foreach($_POST['spec_name'] as $k => $v)
                {
                    $data['spec_sort']   = $_POST['gs_sort'][$k];
                    $data['spec_name']    = $_POST['spec_name'][$k];
                    $data['cost_price']   = $_POST['cost_price'][$k];
                    $data['market_price'] = $_POST['market_price'][$k];
                    $data['price']        = $_POST['price'][$k];
                    $data['is_show']      = $_POST['spec_is_show'][$k];
                    $data['stock']        = $_POST['stock'][$k];
                    $data['label']        = $_POST['label'][$k];
                    $spec_model->addSpec($data);
                }
                $this->log('添加酒店成功'.'[标题:'.$_POST['title'].']',1);
                showMessage(L('nc_common_save_succ'),'index.php?act=hotel&action=index');
            }else{
                showMessage(L('nc_common_save_fail'));
            }
        }
        $cate = $ticket_category->getCategoryList(array('tc_pid'=>1,'is_del'=>0));//获取酒店分类
        $provinces = $area_model->getAreaList(array('parent_id'=>1));
        Tpl::output('cate',$cate);
        Tpl::output('top_link',$this->sublink($this->links,'add'));
        Tpl::output('provinces',$provinces);
        Tpl::output('merchants',$merchants);
        Tpl::showpage('hotel.add');
    }

    /**
     * 编辑酒店
     */
    public function editOp()
    {
        //查询酒店信息
        $hotel_model = Model('hotel');
        $spec_model  = Model('spec');
        $area_model = Model('area');
        $id = intval($_GET['ht_id']);
        $condition = array();
        $condition['id'] = $id;
        $info = $hotel_model->getHotelInfo($condition);
        $info['hotel_thumb'] = UPLOAD . 'hotel/' . $info['hotel_thumb'];
        //获取酒店所有房型
        $spec_list = $spec_model->getSpecListPage(array('goods_id'=>$id,'type'=>1,'parent_id'=>0));
        //获取已经选中市、县
        $citys = $area_model->getAreaList(array('parent_id'=>$info['ht_province_id']));
        $areas = $area_model->getAreaList(array('parent_id'=>$info['ht_city_id']));
        array_push($this->links, array('url'=>'act=ticket&op=edit&tk_id=' .$id ,'lang'=>'nc_edit'));
        $merchant_model = Model('member_merchant');
        if(intval($this->admin_info['merchant_id'])>0){
            $merchants = $merchant_model->getMerchantList(array('mc_status'=>1,'merchant_id'=>$this->admin_info['merchant_id']), 'merchant_id,mc_shop_name');
        }else{
            $merchants = $merchant_model->getMerchantList(array('mc_status'=>1,'is_disable'=>0), 'merchant_id,mc_shop_name');
        }
        $provinces = $area_model->getAreaList(array('parent_id'=>1));
        if(chksubmit()){
            $hotel_model = Model('hotel');
            $insert_array = array();
            $insert_array['hotel_name']          = trim($_POST['title']);
            $insert_array['merchant_id']         = intval($this->admin_info['merchant_id'])>0?intval($this->admin_info['merchant_id']):intval($_POST['merchant_id']);
            $insert_array['ht_market_price']     = floatval($_POST['show_price']);
            $insert_array['hotel_tel']           = $_POST['hotel_tel'];
            //$insert_array['ht_add_time']         = time();
            $insert_array['ht_update_time']      = time();
            $insert_array['ht_addr']             = $_POST['addr'];
            $insert_array['ht_province_id']      = $_POST['province_id'];
            $insert_array['ht_city_id']          = $_POST['city_id'];
            $insert_array['ht_city_name']        = $area_model->getfby_area_id($_POST['city_id'],'name');
            $insert_array['ht_area_id']          = $_POST['area_id'];
            $insert_array['hotel_param_wifi']    = trim($_POST['hotel_param_wifi']);
            $insert_array['hotel_param_part']    = trim($_POST['hotel_param_part']);
            $insert_array['hotel_param_room']    = implode(',', $_POST['hotel_param_room']);
            $insert_array['hotel_param_service'] = implode(',', $_POST['hotel_param_service']);
            $insert_array['hotel_param_base']    = implode(',', $_POST['hotel_param_base']);
            $insert_array['hotel_content']       = $_POST['content'];
            $insert_array['cate_id']             = intval($_POST['cate1']);
            $store_location = trim($_POST['store_location']);
            $store_gps = explode(',', $store_location);

            $insert_array['hotel_lat']  = $store_gps[1];//纬度
            $insert_array['hotel_lng']  = $store_gps[0];//经度

            $insert_array['ht_full_addr']        = implode('',array(
                $area_model->getfby_area_id(intval($_POST['province_id']),'name'),
                $insert_array['ht_city_name'],
                $area_model->getfby_area_id(intval($_POST['area_id']),'name'),
                $_POST['addr']
            ));
            if($_FILES['thumb']['tmp_name']){
                $upload = new UploadFile();
                $upload->set('default_dir','hotel/'.$upload->getSysSetPath());
                $upload->set('thumb_width', GOODS_IMAGES_WIDTH);
                $upload->set('thumb_height', GOODS_IMAGES_HEIGHT);
                $upload->set('thumb_ext', GOODS_IMAGES_EXT);
                $upload->set('allow_type', array('gif', 'jpg', 'jpeg', 'png'));
                //封面图片
                $result = $upload->upfile('thumb');
                if($result){
                    $insert_array['hotel_thumb'] = $upload->getSysSetPath() . $upload->file_name;
                } else {
                    //图片上传失败
                    $this->log('酒店封面图上传失败'.'[标题:'.$_POST['title'].']',0);
                    showMessage(L('nc_common_save_fail').$upload->error);
                }
            }
            $result = $hotel_model->updateHotel(array('id'=>$id),$insert_array);
            if($result){
                foreach($_POST['spec_name'] as $k => $v)
                {
                    $spec_id = $_POST['spec_id'][$k];
                    $data['goods_id'] =  $id;
                    $data['spec_sort']   = $_POST['gs_sort'][$k];
                    $data['spec_name']    = $_POST['spec_name'][$k];
                    $data['cost_price']   = $_POST['cost_price'][$k];
                    $data['market_price'] = $_POST['market_price'][$k];
                    $data['price']        = $_POST['price'][$k];
                    $data['is_show']      = $_POST['spec_is_show'][$k];
                    $data['stock']        = $_POST['stock'][$k];
                    $data['label']        = $_POST['label'][$k];
                    if(empty($spec_id)){
                       $spec_model->addSpec($data);
                    }else{
                        $spec_model->updateSpec(array('spec_id'=>$spec_id),$data);
                    }
                }
                $this->log('编辑酒店成功'.'[标题:'.$_POST['title'].']',1);
                showMessage(L('nc_common_save_succ'),'index.php?act=hotel&action=index');
            }else{
                showMessage(L('nc_common_save_fail'));
            }


        }
        $ticket_category = Model('ticket_category');
        $cate = $ticket_category->getCategoryList(array('tc_pid'=>1,'is_del'=>0));//获取酒店分类
        Tpl::output('cate',$cate);
        Tpl::output('provinces', $provinces);
        Tpl::output('merchants',$merchants);
        Tpl::output('top_link',$this->sublink($this->links,'edit'));
        Tpl::output('hotel_info',$info);
        Tpl::output('spec_list',$spec_list);
        Tpl::output('citys', $citys);
        Tpl::output('areas', $areas);
        //基础信息,相册
        $sublinks = array(
            array('url'=>'act=hotel&op=edit&ht_id=' . $id,'lang'=>'hotel_index_info'),
            array('url'=>'act=hotel&op=photo&ht_id=' . $id,'lang'=>'index_photo')
        );

        Tpl::output('sub_link',$this->sublink($sublinks,'edit'));
        Tpl::showpage('hotel.edit');
    }

    /**
     * 编辑规格
     */
    public function spec_editOp()
    {
        $spec_model = Model('spec');
        $all_spec_id = intval($_GET['spec_id']);
        $spec_info = $spec_model->getSpecInfo(array('spec_id'=>$all_spec_id));
        if(chksubmit()){

            $update_array = array();
            $update_array['spec_name']    = $_POST['all_spec_name'];
            $update_array['market_price'] = $_POST['all_market_price'];
            $update_array['label']        = $_POST['all_label'];
            $update_array['stock']        = $_POST['all_stock'];
            $update_array['is_show']      = $_POST['is_show'];
            $update_array['open_spec']    = $_POST['open_spec'];
            $update_array['true_number']  = $_POST['true_number'];
            $update_array['cost_price']  =  $_POST['cost_price_all'];
            $update_array['shower_oom']   = $_POST['shower_oom'];
            $update_array['floorage']     = $_POST['floorage'];
            $update_array['floor']        = $_POST['floor'];
            $update_array['amenities']    = $_POST['amenities'];
            //var_dump($_POST);exit;
            if($_FILES['thumb']['tmp_name']){
                $upload = new UploadFile();
                $upload->set('default_dir','hotel/'.$upload->getSysSetPath());
                $upload->set('thumb_width', GOODS_IMAGES_WIDTH);
                $upload->set('thumb_height', GOODS_IMAGES_HEIGHT);
                $upload->set('thumb_ext', GOODS_IMAGES_EXT);
                $upload->set('allow_type', array('gif', 'jpg', 'jpeg', 'png'));
                //封面图片
                $result = $upload->upfile('thumb');
                if($result){
                    $update_array['surface_img'] = $upload->getSysSetPath() . $upload->file_name;
                } else {
                    //图片上传失败
                    $this->log('房型封面图上传失败'.'[标题:'.$_POST['title'].']',0);
                    showMessage(L('nc_common_save_fail').$upload->error);
                }
            }
            $result = $spec_model->updateSpec(array('spec_id'=>$all_spec_id,'type'=>1),$update_array);

            if($result && $update_array['open_spec']==1){
                foreach($_POST['spec_name'] as $k => $v){
                    $spec_id = $_POST['spec_id'][$k];
                    $data['goods_id'] =  $spec_info['goods_id'];
                    $data['spec_sort']   = $_POST['gs_sort'][$k];
                    $data['spec_name']    = $_POST['spec_name'][$k];
                    $data['cost_price']   = $_POST['cost_price'][$k];
                    $data['market_price'] = $_POST['market_price'][$k];
                    $data['price']        = $_POST['price'][$k];
                    $data['is_show']      = $_POST['spec_is_show'][$k];
                    $data['stock']        = $_POST['stock'][$k];
                    $data['label']        = $_POST['label'][$k];
                    $data['parent_id']    = $all_spec_id;
                    $data['type'] = 1;
                    if(empty($spec_id)){
                        $data['add_time'] = time();
                        $spec_model->addSpec($data);
                    }else{
                        $spec_model->updateSpec(array('spec_id'=>$spec_id),$data);
                    }
                }
                $this->log('编辑房型成功'.'[标题:'.$_POST['title'].']',1);
                showMessage(L('nc_common_save_succ'),'index.php?act=hotel&op=edit&ht_id='.$spec_info['goods_id']);
            }elseif($result){

                $this->log('编辑房型成功'.'[标题:'.$_POST['title'].']',1);
                showMessage(L('nc_common_save_succ'),'index.php?act=hotel&op=edit&ht_id='.$spec_info['goods_id']);
            }else{
                showMessage(L('nc_common_save_fail'));
            }
        }
        //var_dump($spec_info);exit;
        $sublinks = array(
            array('url'=>'act=hotel&op=edit&ht_id=' . $spec_info['goods_id'],'lang'=>'hotel_index_info'),
            array('url'=>'act=ticket&op=spec_edit&spec_id=' . $spec_id,'lang'=>'hotel_index_room_type')
        );
        //获取房型所有类型
        $spec_list = $spec_model->getSpecListPage(array('type'=>1,'parent_id'=>$all_spec_id));
        //获取封面图
        $spec_info['surface_img'] =  UPLOAD . 'hotel/' .$spec_info['surface_img'];
        //获取图册
        $images_model = Model('spec_images');
        $images = $images_model->getSpecImageList(array('spec_id'=>$all_spec_id, 'img_deleted'=>0));
        if(!empty($images)){
            foreach($images as $key => $vo){
                $images[$key]['img_path'] =  UPLOAD . 'hotel/' .$vo['img_path'];
            }
        }

        Tpl::output('images',$images);
        Tpl::output('spec_list',$spec_list);
        Tpl::output('spec_info',$spec_info);
        Tpl::output('sub_link',$this->sublink($sublinks,'spec_edit'));
        Tpl::showpage('spec_edit');
    }

    /**
     * ajax 上传图片
     */
    public function ajax_imgsOp()
    {
        $images_model = Model('spec_images');
        $spec_id = intval($_GET['spec_id']);
        $upload = new UploadFile();
        $upload->set('default_dir', 'hotel/' . $upload->getSysSetPath());
        $upload->set('thumb_width', GOODS_IMAGES_WIDTH);
        $upload->set('thumb_height', GOODS_IMAGES_HEIGHT);
        $upload->set('thumb_ext', GOODS_IMAGES_EXT);
        $upload->set('allow_type', array('gif', 'jpg', 'jpeg', 'png'));
        $upload->set('thumb_width', GOODS_IMAGES_WIDTH);
        $upload->set('thumb_height', GOODS_IMAGES_HEIGHT);
        $upload->set('thumb_ext', GOODS_IMAGES_EXT);
        $upload->set('allow_type', array('gif', 'jpg', 'jpeg', 'png'));
        $result = $upload->upfile('file');
        if($result){
            //得到图片上传后的路径
            $path = $upload->getSysSetPath() . $upload->file_name;
            $params = array(
                'spec_id' => $spec_id,
                'img_size' => round($_FILES['file']['size'] / 1024),
                'img_ext' => $upload->ext,
                'img_path' => $path,
                'img_addtime' => time(),
            );
            //保存到数据库
            if ($img_id = $images_model->addSpecImage($params)) {
                $this->log('添加房型图片'.'[房型ID:'.$spec_id.'][img_id:'.$img_id.']', 1);
                exit(json_encode(array(
                    'res' => true,
                    'id' => $img_id,
                    'path' => UPLOAD . 'hotel/' . $path
                )));
            }
        }
        $this->log('添加房型图册'.'[房型ID:'.$spec_id.']', 0);
        exit(json_encode(array('res'=>false)));
    }
    /**
     * ajax删除照片
     */
    public function delimgOp()
    {
        $img_id = intval($_POST['img_id']);
        /* @var ticket_imagesModel $images_model */
        $images_model = Model('spec_images');
        $res = $images_model->delSpecImage(array('img_id'=>$img_id));
        $this->log('删除房型图片成功'.'[img_id:'.$img_id.']', $res?1:0);
        exit(json_encode(array('res'=>$res)));
    }
    /**
     * 删除规格
     */
    public function delete_specOp()
    {
        $spec_id = intval($_POST['spec_id']);
        $spec_model = Model('spec');
        if($spec_id>0){
            $condition = array();
            $info = $spec_model->getSpecInfo(array('spec_id'=>$spec_id));
            if(empty($info)){
                die(json_encode(array('tab' => 'error', 'info' => '规格不存在')));
            }

            $condition['spec_id'] = $spec_id;
            $condition['type'] = 1;
            if($spec_model->deleteSpec($condition)){
                $spec_model->deleteSpec(array('parent_id'=>$spec_id));//删除底下的子分类
                die(json_encode(array('tab' => 'success', 'info' => '删除成功')));
            }
            die(json_encode(array('tab' => 'error', 'info' => '删除失败')));
        }
        die(json_encode(array('tab' => 'error', 'info' => '非法操作')));
    }
    /**
     * ajax更改上架状态
     */
    public function  ajaxstatusOp()
    {
        /* @var ticketModel $ticket_model */
        $ticket_model = Model('hotel');

        $type = $_GET['type'];

        switch ($type) {
            case 'change_recommend':
                $tk_id = $_POST['tk_id'];
                $tk = $ticket_model->getHotelInfo(array('id'=>$tk_id));
                if ($tk) {
                    $recommend = $tk['tk_is_recommend'] ? 0 : 1;
                    $res = $ticket_model->updateHotel(array('id'=>$tk_id), array('tk_is_recommend'=>$recommend));
                    $action = $recommend ? 'ticket_add_recommend' : 'ticket_index_not_recommend';
                    $this->log(L('ticket_index_ticket,'.$action).'[id:'.$tk_id.']', $res?1:0);
                    exit(json_encode(array('res'=>$res, 'new_recommend'=>$recommend)));
                } else {
                    exit(json_encode(array('res'=>false, 'new_recommend'=>'')));
                }
            case 'change_status':
                $tk_id = $_POST['tk_id'];
                $tk = $ticket_model->getHotelInfo(array('id'=>$tk_id));
                if ($tk) {
                    $status = $tk['ht_status'] ? 0 : 1;
                    $res = $ticket_model->updateHotel(array('id'=>$tk_id), array('ht_status'=>$status));
                    $action = $status ? 'ticket_index_show' : 'ticket_index_hide';
                    $this->log('酒店'.L($action).'[tk_id:'.$tk_id.']', $res?1:0);
                    exit(json_encode(array('res'=>$res, 'new_status'=>$status)));
                } else {
                    exit(json_encode(array('res'=>false, 'new_status'=>'')));
                }
            case 'change_all':
                $ids = $_POST['ids'];
                $status = $_POST['type'] == 'show' ? 1 : 0;
                $condition = array(
                    'id' => array('in', implode(',', $ids))
                );
                $res = $ticket_model->updateHotel($condition, array('ht_status'=>$status));
                $action = $status ? 'ticket_index_show' : 'ticket_index_hide';
                $this->log('酒店'.L($action).'[id:'.implode(',',$ids).']', $res?1:0);
                exit(json_encode(array('res'=>$res)));
        }
    }

    /**
     * 获取地理坐标
     */
    public function bdmapOp(){
        $model = Model('area');
        $cityId = trim($_GET['cityId']);
        $areaId = trim($_GET['areaId']);
        $proviceId = trim($_GET['proviceId']);//省ID
        $store_address= trim($_GET['store_address']);
        $proviceId = $model->getfby_id($proviceId,'name');
        $cityName = $model->getfby_id($cityId,'name');
        $areaName = $model->getfby_id($areaId,'name');
        Tpl::output('region', $proviceId.$cityName.$areaName);
        Tpl::output('store_address', $store_address);
        Tpl::setDir('');
        Tpl::showpage('gdmap', 'null_layout');
    }

    /**
     * 酒店相册
     */
    public function photoOp()
    {
        $tk_id = intval($_GET['ht_id']);
        /* @var ticket_imagesModel $images_model */
        $images_model = Model('ticket_images');

      if(chksubmit()){
          $images_facade = $_POST['images_facade'];//外观图册
          if(!empty($images_facade)){
              foreach($images_facade as $val){
                  $param = array();
                  $param['tk_id'] = $tk_id;
                  $param['img_path'] = $val;
                  $param['img_ext']  = pathinfo($val,PATHINFO_EXTENSION);
                  $param['img_size'] = round(filesize(BASE_DATA_PATH.DS.'upload'.DS.'hotel'.DS.$val) /1024);
                  $param['img_addtime'] = time();
                  $param['cate'] = 1;
                  $param['type'] = HOTEL_MARK;
                  $images_model->addTicketImage($param);
              }
          }
          $images_lobby = $_POST['images_lobby']; //大厅相册
          if(!empty($images_lobby)){
              foreach($images_lobby as $val){
                  $param = array();
                  $param['tk_id'] = $tk_id;
                  $param['img_path'] = $val;
                  $param['img_ext']  = pathinfo($val,PATHINFO_EXTENSION);
                  $param['img_size'] = round(filesize(BASE_DATA_PATH.DS.'upload'.DS.'hotel'.DS.$val) /1024);
                  $param['img_addtime'] = time();
                  $param['cate'] = 2;
                  $param['type'] = HOTEL_MARK;
                  $images_model->addTicketImage($param);
              }
          }
          $images_dining = $_POST['images_dining']; //餐厅相册
          if(!empty($images_lobby)){
              foreach($images_dining as $val){
                  $param = array();
                  $param['tk_id'] = $tk_id;
                  $param['img_path'] = $val;
                  $param['img_ext']  = pathinfo($val,PATHINFO_EXTENSION);
                  $param['img_size'] = round(filesize(BASE_DATA_PATH.DS.'upload'.DS.'hotel'.DS.$val) /1024);
                  $param['img_addtime'] = time();
                  $param['cate'] = 3;
                  $param['type'] = HOTEL_MARK;
                  $images_model->addTicketImage($param);
              }
          }

          $this->log('添加酒店相册成功'.'[tk_id:'.$tk_id.']', 1);
          showMessage(L('nc_common_save_succ'), 'index.php?act=hotel&op=edit&ht_id='.$tk_id);
      }

        Tpl::output('tk_id', $tk_id);
        $images = $images_model->getTicketImageList(array('tk_id'=>$tk_id, 'img_deleted'=>0,'type'=>HOTEL_MARK));
        foreach ($images as $k => $img) {
            $images[$k]['img_path'] = UPLOAD . 'hotel/' . $img['img_path'];
        }
        Tpl::output('images',$images);

        array_push($this->links, array('url'=>'act=hotel&op=edit&ht_id=' . $tk_id,'lang'=>'nc_edit'));
        Tpl::output('top_link',$this->sublink($this->links,'edit'));
        //基础信息,相册
        $sublinks = array(
            array('url'=>'act=hotel&op=edit&ht_id=' . $tk_id,'lang'=>'hotel_index_info'),
            array('url'=>'act=hotel&op=photo&ht_id=' . $tk_id,'lang'=>'index_photo')
        );
        Tpl::output('sub_link',$this->sublink($sublinks,'photo'));
        Tpl::showpage('hotel.photo');
    }

    /**
     * 设置酒店房型关闭日期
     */
    public function close_hotelOp()
    {
        $merchant_id = intval($this->admin_info['merchant_id']);
        if($merchant_id>0){
            /* @var hotelModel $hotel_model*/
            $hotel_model = Model('hotel');
            $hotel_info = $hotel_model->getHotelInfo(array('merchant_id'=>$merchant_id));
            if(empty($hotel_info)){
                showMessage('您还没有添加属于自己的酒店呢,请先添加', 'index.php?act=hotel&op=add');
            }
            /* @var hotel_dateModel $date_model */
            $date_model = Model('hotel_date');
            /* @var hotel_close_dateModel $close_model */
            $close_model = Model('hotel_close_date');
            /* @var specModel $spec_model */
            $spec_model = Model('spec');
            $date_list = $date_model->getHotelDateListPage(array('ht_id'=>$hotel_info['id']),"*",20);
            foreach ($date_list as $k => $date) {
                $date_list[$k]['close'] = $close_model->getHotelSpecSkuList(array('date_id'=>$date['date_id']));
            }
            //var_dump($date_list);
            //获取该门票底下的所有规格
            $spec_list = $spec_model->getSpecList(array('goods_id'=>$hotel_info['id'],'type'=>HOTEL_MARK,'parent_id'=>0));
            Tpl::output('page',$date_model->showpage());
            Tpl::output('list',$date_list);
            Tpl::output('spec_list',$spec_list);
            Tpl::output('hotel_info',$hotel_info);
            Tpl::showpage('hotel.days');
        }else{
            showMessage('您还没有添加属于自己的酒店,请先添加');
        }
    }

    /**
     * 房型每日状态ajax控制
     */
    public function close_ajaxOp()
    {
        $lang	= Language::getLangContent();
        $type = $_GET['type'];

        /* @var hotel_dateModel $date_model */
        $date_model = Model('hotel_date');
        /* @var hotel_close_dateModel $close_model */
        $close_model = Model('hotel_close_date');
        switch ($type) {
            case 'add' :
                $time = time();
                $params = array(
                    'ht_id' => intval($_POST['ht_id']),
                    'date' => $_POST['date'],
                    'spec_id'=>implode('#',array_keys($_POST['specs'])),
                );
                $old = $date_model->getHotelDateInfo($params);
                if($old){
                    $res = json_encode(array('res'=>false, 'msg'=>$lang['ticket_day_date_same']));
                }else{
                    Model::beginTransaction();
                    try{
                        $params['date_time'] = $time;
                        $data_id =  $date_model->addHotelDate($params);
                        if($data_id){
                            foreach($_POST['specs'] as $key=>$value){
                                $sku_params = array(
                                    'date_id'=>$data_id,
                                    'spec_id'=>$key,
                                );
                                $close_model->addHotelSpecClose($sku_params);
                            }
                            Model::commit();
                            $res = json_encode(array('res'=>true, 'msg'=>$lang['nc_common_save_succ']));
                        }else{
                            Model::rollback();
                            $res = json_encode(array('res'=>false, 'msg'=>$lang['nc_common_save_fail']));
                        }
                    }catch(\Exception $e){
                        Model::rollback();
                        $res = json_encode(array('res'=>false, 'msg'=>$lang['nc_common_save_fail']));
                    }
                }
                $this->log('添加房型状态'.'[date_id:'.$data_id.']', $res ? 1 : 0);
                exit($res);
            case 'info' :
                $date_id = $_POST['date_id'];
                $date_info = $date_model->getHotelDateInfo(array('date_id'=>$date_id));
                $date_info['close'] = $close_model->getHotelSpecSkuList(array('date_id'=>$date_id));
                exit(json_encode($date_info));
            case 'update':
                $date_id = $_POST['date_id'];
                $specs = array_keys($_POST['specs']);
                Model::beginTransaction();
                try{
                    //先删除 再添加
                    $specs && $close_model->delHotelSpecClose(array(
                        'date_id' => $date_id,
                    ));
                    $date_model->updateHotelDate(array('date_id'=>$date_id),array('spec_id'=>implode('#',$specs)));
                    foreach($specs as $key => $value){
                        $sku_params = array(
                            'date_id'=>$date_id,
                            'spec_id'=>$value,
                        );
                        $close_model->addHotelSpecClose($sku_params);
                    }
                    Model::commit();
                    $res = json_encode(array('res'=>true, 'msg'=>$lang['nc_common_save_succ']));
                }catch(\Exception $e){
                    Model::rollback();
                    $res = json_encode(array('res'=>false, 'msg'=>$lang['nc_common_save_fail']));
                }
                $this->log('编辑房型状态'.'[date_id:'.$date_id.']', $res ? 1 : 0);
                exit($res);
            case 'del' :
                $date_id = $_POST['date_id'];
                Model::beginTransaction();
                $res = $date_model->delHotelDate(array('date_id'=>$date_id)) && $close_model->delHotelSpecClose(array('date_id'=>$date_id));
                $res ? Model::commit() : Model::rollback();
                $this->log('删除房型状态'.'[date_id:'.$date_id.']', $res?1:0);
                exit($res);
            case 'del_all':
                $ids = $_POST['ids'];
                $condition = array(
                    'date_id' => array('in', implode(',', $ids))
                );
                Model::beginTransaction();
                $res = $date_model->delHotelDate($condition) && $close_model->delHotelSpecClose($condition);
                $res ? Model::commit() : Model::rollback();
                $this->log('批量删除房型状态'.'[date_id:'.implode(',', $ids).']', $res?1:0);
                exit($res);
        }
    }

    /**
     * 删除酒店
     */
    public function del_hotelOp()
    {
        $ht_id = $_POST['ht_id'];
        if($ht_id>0){
            /* @var hotelModel $hotel_model*/
            $hotel_model = Model('hotel');
            /* @var specModel $spec_model */
            $spec_model = Model('spec');
            $ht = $hotel_model->getHotelInfo(array('id'=>$ht_id));
            if($ht){
                $res = $hotel_model->deleteHotel(array('id'=>$ht_id));
                $res_ = $spec_model->deleteSpec(array('goods_id'=>$ht_id,'type'=>HOTEL_MARK));
                if($res && $res_){
                    exit(json_encode(array('res'=>true, 'msg_'=>'成功')));
                }else{
                    exit(json_encode(array('res'=>false, 'msg_'=>'删除失败')));
                }
            }else{
                exit(json_encode(array('res'=>false, 'msg_'=>'酒店不存在')));
            }
        }
    }

}